package com.learn.grpc.hello;

import io.grpc.Server;
import io.grpc.ServerBuilder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HelloServiceGrpcServer {

    public static final int serverPort = 9091;

    public static void main(String[] args) throws Exception{

        //1. 创建 server 构造器
        ServerBuilder<?> serverBuilder = ServerBuilder.forPort(serverPort);

        //2. 添加暴露的服务
        serverBuilder.addService(new HelloServiceGrpcImpl());

        //3. 构建 Server
        Server server = serverBuilder.build();

        //4. 启动服务
        server.start();

        log.info("服务启动成功, 端口号:" + serverPort);

        // 等待停止
        server.awaitTermination();

    }
}
